package com.susallwave.srcb.controller.sys.others;

import com.susallwave.srcb.schedule.RetryDistributedLock;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * fastExcel
 * </p>
 *
 * @author MyBatisPlusGenerator * @since 2025-07-22
 */
@RestController
@RequestMapping("/schedule")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "定时任务", description = "定时任务")
public class ScheduleController {

    @Autowired
    private Map<String, RetryDistributedLock> tasks;

    // 通过任务名触发任务执行
    @PostMapping("/run/{taskName}")
    public String runTask(@PathVariable String taskName) {
        RetryDistributedLock task = tasks.get(taskName);
        if (task == null) {
            return "任务不存在: " + taskName;
        }
        String msg = task.run();
        return msg;
    }
}
